﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibHuman;

namespace Human
{
	/// <summary>
	/// Summary description for frmBangcap.
	/// </summary>
	public class frmdmnganhang : System.Windows.Forms.Form
	{
        private AccessData mDB = new AccessData();
        Language lan = new Language();
		private DataSet ds=new DataSet();
		private System.Windows.Forms.DataGrid dgrDanhMuc5;
		private System.Windows.Forms.Panel panel1;
		private PinkieControls.ButtonXP btnSua;
		private PinkieControls.ButtonXP btnBoqua;
		private PinkieControls.ButtonXP btnHuy;
		private PinkieControls.ButtonXP btnThem;
		private PinkieControls.ButtonXP btnLuu;
		private PinkieControls.ButtonXP btnKetthuc;
		private System.Windows.Forms.TextBox txtTen;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox txtMa;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmdmnganhang()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
            lan.Read_Language_to_Xml(this.Name.ToString(), this);
            lan.Changelanguage_to_English(this.Name.ToString(), this);
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmdmnganhang));
            this.dgrDanhMuc5 = new System.Windows.Forms.DataGrid();
            this.panel1 = new System.Windows.Forms.Panel();
            this.btnSua = new PinkieControls.ButtonXP();
            this.btnBoqua = new PinkieControls.ButtonXP();
            this.btnHuy = new PinkieControls.ButtonXP();
            this.btnThem = new PinkieControls.ButtonXP();
            this.btnLuu = new PinkieControls.ButtonXP();
            this.btnKetthuc = new PinkieControls.ButtonXP();
            this.txtTen = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.label1 = new System.Windows.Forms.Label();
            this.txtMa = new System.Windows.Forms.TextBox();
            ((System.ComponentModel.ISupportInitialize)(this.dgrDanhMuc5)).BeginInit();
            this.panel1.SuspendLayout();
            this.SuspendLayout();
            // 
            // dgrDanhMuc5
            // 
            this.dgrDanhMuc5.AlternatingBackColor = System.Drawing.Color.Lavender;
            this.dgrDanhMuc5.BackColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDanhMuc5.BackgroundColor = System.Drawing.SystemColors.Control;
            this.dgrDanhMuc5.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.dgrDanhMuc5.CaptionBackColor = System.Drawing.Color.LightSteelBlue;
            this.dgrDanhMuc5.CaptionForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc5.CaptionVisible = false;
            this.dgrDanhMuc5.DataMember = "";
            this.dgrDanhMuc5.FlatMode = true;
            this.dgrDanhMuc5.Font = new System.Drawing.Font("Tahoma", 8F);
            this.dgrDanhMuc5.ForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc5.GridLineColor = System.Drawing.Color.Gainsboro;
            this.dgrDanhMuc5.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
            this.dgrDanhMuc5.HeaderBackColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc5.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
            this.dgrDanhMuc5.HeaderForeColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDanhMuc5.LinkColor = System.Drawing.Color.Teal;
            this.dgrDanhMuc5.Location = new System.Drawing.Point(8, 6);
            this.dgrDanhMuc5.Name = "dgrDanhMuc5";
            this.dgrDanhMuc5.ParentRowsBackColor = System.Drawing.Color.Gainsboro;
            this.dgrDanhMuc5.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc5.RowHeaderWidth = 10;
            this.dgrDanhMuc5.SelectionBackColor = System.Drawing.Color.CadetBlue;
            this.dgrDanhMuc5.SelectionForeColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDanhMuc5.Size = new System.Drawing.Size(404, 286);
            this.dgrDanhMuc5.TabIndex = 16;
            this.dgrDanhMuc5.CurrentCellChanged += new System.EventHandler(this.dgrDanhMuc5_CurrentCellChanged);
            // 
            // panel1
            // 
            this.panel1.Controls.Add(this.btnSua);
            this.panel1.Controls.Add(this.btnBoqua);
            this.panel1.Controls.Add(this.btnHuy);
            this.panel1.Controls.Add(this.btnThem);
            this.panel1.Controls.Add(this.btnLuu);
            this.panel1.Controls.Add(this.btnKetthuc);
            this.panel1.Location = new System.Drawing.Point(7, 354);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(409, 36);
            this.panel1.TabIndex = 127;
            // 
            // btnSua
            // 
            this.btnSua.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240)))));
            this.btnSua.DefaultScheme = true;
            this.btnSua.DialogResult = System.Windows.Forms.DialogResult.None;
            this.btnSua.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnSua.ForeColor = System.Drawing.Color.DarkBlue;
            this.btnSua.Hint = "";
            this.btnSua.Location = new System.Drawing.Point(66, 4);
            this.btnSua.Name = "btnSua";
            this.btnSua.Scheme = PinkieControls.ButtonXP.Schemes.Blue;
            this.btnSua.Size = new System.Drawing.Size(63, 28);
            this.btnSua.TabIndex = 2;
            this.btnSua.Text = "&Sửa";
            this.btnSua.TextColor = System.Drawing.Color.DarkBlue;
            this.btnSua.Click += new System.EventHandler(this.btnSua_Click);
            // 
            // btnBoqua
            // 
            this.btnBoqua.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240)))));
            this.btnBoqua.DefaultScheme = true;
            this.btnBoqua.DialogResult = System.Windows.Forms.DialogResult.None;
            this.btnBoqua.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnBoqua.ForeColor = System.Drawing.Color.DarkBlue;
            this.btnBoqua.Hint = "";
            this.btnBoqua.Image = ((System.Drawing.Image)(resources.GetObject("btnBoqua.Image")));
            this.btnBoqua.Location = new System.Drawing.Point(194, 4);
            this.btnBoqua.Name = "btnBoqua";
            this.btnBoqua.Scheme = PinkieControls.ButtonXP.Schemes.Blue;
            this.btnBoqua.Size = new System.Drawing.Size(74, 28);
            this.btnBoqua.TabIndex = 4;
            this.btnBoqua.Text = "&Bỏ qua";
            this.btnBoqua.TextColor = System.Drawing.Color.DarkBlue;
            this.btnBoqua.Click += new System.EventHandler(this.btnBoqua_Click);
            // 
            // btnHuy
            // 
            this.btnHuy.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240)))));
            this.btnHuy.DefaultScheme = true;
            this.btnHuy.DialogResult = System.Windows.Forms.DialogResult.None;
            this.btnHuy.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnHuy.ForeColor = System.Drawing.Color.DarkBlue;
            this.btnHuy.Hint = "";
            this.btnHuy.Image = ((System.Drawing.Image)(resources.GetObject("btnHuy.Image")));
            this.btnHuy.Location = new System.Drawing.Point(269, 4);
            this.btnHuy.Name = "btnHuy";
            this.btnHuy.Scheme = PinkieControls.ButtonXP.Schemes.Blue;
            this.btnHuy.Size = new System.Drawing.Size(61, 28);
            this.btnHuy.TabIndex = 5;
            this.btnHuy.Text = "&Xoá ";
            this.btnHuy.TextColor = System.Drawing.Color.DarkBlue;
            this.btnHuy.Click += new System.EventHandler(this.btnHuy_Click);
            // 
            // btnThem
            // 
            this.btnThem.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240)))));
            this.btnThem.DefaultScheme = true;
            this.btnThem.DialogResult = System.Windows.Forms.DialogResult.None;
            this.btnThem.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnThem.ForeColor = System.Drawing.Color.DarkBlue;
            this.btnThem.Hint = "";
            this.btnThem.Image = ((System.Drawing.Image)(resources.GetObject("btnThem.Image")));
            this.btnThem.Location = new System.Drawing.Point(4, 4);
            this.btnThem.Name = "btnThem";
            this.btnThem.Scheme = PinkieControls.ButtonXP.Schemes.Blue;
            this.btnThem.Size = new System.Drawing.Size(63, 28);
            this.btnThem.TabIndex = 1;
            this.btnThem.Text = "&Mới";
            this.btnThem.TextColor = System.Drawing.Color.DarkBlue;
            this.btnThem.Click += new System.EventHandler(this.btnThem_Click);
            // 
            // btnLuu
            // 
            this.btnLuu.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240)))));
            this.btnLuu.DefaultScheme = true;
            this.btnLuu.DialogResult = System.Windows.Forms.DialogResult.None;
            this.btnLuu.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnLuu.ForeColor = System.Drawing.Color.DarkBlue;
            this.btnLuu.Hint = "";
            this.btnLuu.Image = ((System.Drawing.Image)(resources.GetObject("btnLuu.Image")));
            this.btnLuu.Location = new System.Drawing.Point(130, 4);
            this.btnLuu.Name = "btnLuu";
            this.btnLuu.Scheme = PinkieControls.ButtonXP.Schemes.Blue;
            this.btnLuu.Size = new System.Drawing.Size(63, 28);
            this.btnLuu.TabIndex = 3;
            this.btnLuu.Text = "&Lưu";
            this.btnLuu.TextColor = System.Drawing.Color.DarkBlue;
            this.btnLuu.Click += new System.EventHandler(this.btnLuu_Click);
            // 
            // btnKetthuc
            // 
            this.btnKetthuc.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240)))));
            this.btnKetthuc.DefaultScheme = true;
            this.btnKetthuc.DialogResult = System.Windows.Forms.DialogResult.None;
            this.btnKetthuc.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnKetthuc.ForeColor = System.Drawing.Color.DarkBlue;
            this.btnKetthuc.Hint = "";
            this.btnKetthuc.Image = ((System.Drawing.Image)(resources.GetObject("btnKetthuc.Image")));
            this.btnKetthuc.Location = new System.Drawing.Point(331, 4);
            this.btnKetthuc.Name = "btnKetthuc";
            this.btnKetthuc.Scheme = PinkieControls.ButtonXP.Schemes.Blue;
            this.btnKetthuc.Size = new System.Drawing.Size(71, 28);
            this.btnKetthuc.TabIndex = 6;
            this.btnKetthuc.Text = "&Thoát";
            this.btnKetthuc.TextColor = System.Drawing.Color.DarkBlue;
            this.btnKetthuc.Click += new System.EventHandler(this.btnKetthuc_Click);
            // 
            // txtTen
            // 
            this.txtTen.BackColor = System.Drawing.Color.White;
            this.txtTen.ForeColor = System.Drawing.Color.DarkBlue;
            this.txtTen.Location = new System.Drawing.Point(91, 324);
            this.txtTen.Name = "txtTen";
            this.txtTen.Size = new System.Drawing.Size(323, 20);
            this.txtTen.TabIndex = 126;
            this.txtTen.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtTen_KeyDown);
            // 
            // label2
            // 
            this.label2.BackColor = System.Drawing.SystemColors.Control;
            this.label2.ForeColor = System.Drawing.Color.DarkBlue;
            this.label2.Location = new System.Drawing.Point(88, 308);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(80, 13);
            this.label2.TabIndex = 125;
            this.label2.Text = "Tên ngân hàng";
            this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label1
            // 
            this.label1.BackColor = System.Drawing.SystemColors.Control;
            this.label1.ForeColor = System.Drawing.Color.DarkBlue;
            this.label1.Location = new System.Drawing.Point(18, 308);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(22, 13);
            this.label1.TabIndex = 123;
            this.label1.Text = "Mã ";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // txtMa
            // 
            this.txtMa.BackColor = System.Drawing.Color.White;
            this.txtMa.Enabled = false;
            this.txtMa.ForeColor = System.Drawing.Color.DarkBlue;
            this.txtMa.Location = new System.Drawing.Point(18, 325);
            this.txtMa.Name = "txtMa";
            this.txtMa.Size = new System.Drawing.Size(64, 20);
            this.txtMa.TabIndex = 124;
            this.txtMa.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtMa_KeyDown);
            // 
            // frmdmnganhang
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(431, 401);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.txtTen);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.txtMa);
            this.Controls.Add(this.dgrDanhMuc5);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "frmdmnganhang";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Danh mục ngân hàng";
            this.Load += new System.EventHandler(this.frmBangcap_Load);
            ((System.ComponentModel.ISupportInitialize)(this.dgrDanhMuc5)).EndInit();
            this.panel1.ResumeLayout(false);
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		private void frmBangcap_Load(object sender, System.EventArgs e)
		{
			bangcap();
		}
		private void bangcap() 	
		{
			DataSet ds1=new DataSet();
			ds1=mDB.get_data("SELECT * FROM "+mDB.user+".dmnganhang order by ma");
			dgrDanhMuc5.DataSource=null;
			dgrDanhMuc5.TableStyles.Clear();
			DataGridTableStyle ts = new DataGridTableStyle();
			ts.MappingName = ds1.Tables[0].TableName;
		
			ts.AlternatingBackColor = Color.Beige;
			ts.BackColor = Color.GhostWhite;
			ts.ForeColor = Color.MidnightBlue;
			ts.GridLineColor = Color.RoyalBlue;
			ts.HeaderBackColor = Color.MidnightBlue;
			ts.HeaderForeColor = Color.Lavender;
			ts.SelectionBackColor = Color.Teal;
			ts.SelectionForeColor = Color.PaleGreen;
			
			DataGridTextBoxColumn TextCol1=new DataGridTextBoxColumn();
			TextCol1.MappingName = "ma";
            TextCol1.HeaderText = lan.Change_language_MessageText("Mã ngân hàng");
			TextCol1.Width = 100;
			TextCol1.ReadOnly=true;
			TextCol1.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol1);
			dgrDanhMuc5.TableStyles.Add(ts);
		
			DataGridTextBoxColumn TextCol2=new DataGridTextBoxColumn();
			TextCol2.MappingName = "tennganhang";
            TextCol2.HeaderText = lan.Change_language_MessageText("Tên ngân hàng");
			TextCol2.Width = 270;
			TextCol2.ReadOnly=true;
			TextCol2.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol2);
			dgrDanhMuc5.TableStyles.Add(ts);
		
			ts.DataGrid.DataSource=ds1.Tables[0];
            CurrencyManager cm = (CurrencyManager)BindingContext[dgrDanhMuc5.DataSource, dgrDanhMuc5.DataMember];
            DataView dv = (DataView)cm.List;
            dv.AllowNew = false;
            dv.AllowEdit = false;
            dv.AllowDelete = false;
		}

		private void btnThem_Click(object sender, System.EventArgs e)
		{
			Ena_control(false);
			Ena_textbox(true);
			clear_Text();
			ds=mDB.get_data("SELECT Max(ma) as max_ma FROM "+mDB.user+".dmnganhang");
            int m_tam = 0;
            try
            {
                m_tam = int.Parse(ds.Tables[0].Rows[0][0].ToString()) + 1;
            }
            catch
            {
                m_tam = 1;
            }
			txtMa.Text=m_tam.ToString();//.PadLeft(2,'0').ToString();					
			txtTen.Focus();
		}
		private void Ena_control(bool ena)
		{
			btnThem.Enabled=ena;
			btnSua.Enabled=ena;
			btnLuu.Enabled=!ena;
			btnBoqua.Enabled=!ena;
			btnHuy.Enabled=ena;
			btnKetthuc.Enabled=ena;
		}
		private void Ena_textbox(bool ena)
		{			
			txtTen.Enabled=ena;
		}
		private void clear_Text()
		{			
			txtTen.Clear();
		}
		private void refresh_Text()
		{
			int i=dgrDanhMuc5.CurrentRowIndex;
			if(i>=0)
			{
				txtMa.Text=dgrDanhMuc5[i,0].ToString();
				txtTen.Text=dgrDanhMuc5[i,1].ToString();
			}
		}
		private void btnSua_Click(object sender, System.EventArgs e)
		{
			Ena_control(false);
			Ena_textbox(false);		
			txtTen.Enabled=true;
			txtTen.Focus();
		}

		private void btnLuu_Click(object sender, System.EventArgs e)
		{
			try
			{
				mDB.upd_dmnganhang(int.Parse(txtMa.Text),txtTen.Text);
				bangcap();	
				Ena_control(true);				
				Ena_textbox(false);
				btnThem.Focus();
			}
			catch{}
		}

		private void btnBoqua_Click(object sender, System.EventArgs e)
		{
			Ena_control(true);
			txtTen.Enabled=false;
			refresh_Text();
			btnKetthuc.Focus();
		}

		private void btnHuy_Click(object sender, System.EventArgs e)
		{
			DialogResult dr = MessageBox.Show(lan.Change_language_MessageText("Đồng ý huỷ thông tin này?"),AccessData.Msg,MessageBoxButtons.YesNo);			
			if(dr == DialogResult.Yes) 			
			{
				mDB.get_data("DELETE  FROM "+mDB.user+".dmnganhang WHERE ma="+txtMa.Text.Trim());
			}
			bangcap();
			refresh_Text();		
		}

		private void btnKetthuc_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void dgrDanhMuc5_CurrentCellChanged(object sender, System.EventArgs e)
		{
			try
			{
				refresh_Text();
			}
			catch{}
		}

        private void txtMa_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode==Keys.Enter)
                SendKeys.Send("{Tab}");
        }

        private void txtTen_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                SendKeys.Send("{Tab}");
        }
	}
}
